package com.useeinfo.oa.common.utils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Date;

/**
 * 
* <p>Title: SmsBase.java</p>

* <p>Description:系统手机短信发送类，结合第三方短信平台进行管理使用 </p>

 */
public class SmsBase {
	private static String url="http://221.179.180.158:9008/HttpQuickProcess/submitMessageAll";
	private static String OperID="lprj1";
	private static String OperPass="lprjian";
	private static String AppendID="";

	public static void main(String[] args)throws Exception {
		System.out.println(sendSms("13179610301", "123131"));
	}

	public static String sendSms(String mobile, String content)
			throws UnsupportedEncodingException {
		Integer x_ac = 10;// 发送信息
		HttpURLConnection httpconn = null;
		String result = "-20";
		String memo = content.length() < 70 ? content.trim() : content.trim()
				.substring(0, 70);
		StringBuilder sb = new StringBuilder();
		sb.append(url);
		sb.append("?OperID=").append(OperID);
		sb.append("&OperPass=").append(OperPass);
		sb.append("&DesMobile=").append(mobile);
		//sb.append("&SendTime =").append(CommUtil.formatLongDate(new Date()));
		//sb.append("&AppendID =").append(AppendID);
		sb.append("&Content=").append(URLEncoder.encode(URLEncoder.encode(content,"GBK"),"GBK")); // 注意乱码的话换成GBK编码
		System.out.println(sb.toString());
		try {
			URL url = new URL(sb.toString());
			httpconn = (HttpURLConnection) url.openConnection();
			BufferedReader rd = new BufferedReader(new InputStreamReader(
					httpconn.getInputStream()));
			result = rd.readLine();
			rd.close();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (httpconn != null) {
				httpconn.disconnect();
				httpconn = null;
			}

		}
		System.out.println("result=========="+result);
		return result;
	}
}
